<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-3-30
 * Time: 下午2:28
 */

namespace api\modules\chedai\components;


use common\components\tools\Tools;
use common\models\AndroidAppVersions;
use phpDocumentor\Reflection\Types\Self_;
use yii\base\Component;

class OnlineVerify extends Component
{
    const FACE_SIGN_NOT = '00';
    const VIDEO_UPLOADED = '01';
    const FACE_SIGN_FAILED = '10';
    const FACE_SIGN_PASS = '11';
    const FACE_SIGN_NO_SURE = '12';
    const FACE_SIGN_HAS_MOVED = '13';

    const FACE_CHECK_PASS = 1;
    const FACE_CHECK_FAILED = 0;

    public static function getFaceSignStatus()
    {
        return [
            self::FACE_SIGN_NOT => '未面签',
            self::VIDEO_UPLOADED => '视频已上传',
            self::FACE_SIGN_FAILED => '面签未通过',
            self::FACE_SIGN_PASS => '面签通过',
            self::FACE_SIGN_NO_SURE => '面签结果未确认',
            self::FACE_SIGN_HAS_MOVED => '面签结果已移交',
        ];
    }

    public static function getApiSdkUrl()
    {
        $url = Config::$online_verify['api_sdk_url'];
        return $url;
    }

    public static function getApiServiceUrlTmp()
    {
//        $url = Config::$online_verify['api_service_url_tmp'];
        $url = self::getApiServiceUrl();
        return $url;
    }

    public static function getApiServiceUrl()
    {
//        $bs = Config::$online_verify['api_service_url'];
//        if (\Yii::$app->request->post('uid') == 1255){
//            $bs = Self::getApiServiceUrlTmp();
//        }
        $bs = Config::$online_verify['api_service_url'];
        return $bs;
    }

    public static function getAccount()
    {
        $account = Config::$online_verify['account'];
        return $account;
    }

    public static function getPassword()
    {
        $password = Config::$online_verify['password'];
        return md5($password);
    }

    public static function getVersions()
    {
        $lv = AndroidAppVersions::getInUse();
        $i = $lv->interview;
        $vs = $i?Tools::formatArrStrToArr($i):[];
        return $vs;
    }

    public static function getAppKey()
    {
        return Config::$online_verify['app_key'];
    }

    public static function getAppSecret()
    {
        return Config::$online_verify['app_secret'];
    }

    public static function getHeaders()
    {
        $t = time();
        $nonce = $t.\Yii::$app->security->generateRandomString(40);
        $sign = sha1(self::getAppSecret().$nonce.$t);
        $headers = [
            'AppKey' => self::getAppKey(),
            'CurTime' => $t,
            'Nonce' => $nonce,
            'Sign' => $sign,
        ];
        return $headers;
    }
}